{% extends "contest/base.html" %}
{% load full_time %}
{% load get_attr %}
{% load ranklist_firstac_sign %}
{% block contest_page_title %}比赛参数设置 - {% endblock %}
{% block contest_page_body %}
    {% if contest.start_time == 0 %}
        <div class="alert alert-warning">
        <span class="glyphicon glyphicon-info-sign"></span>&nbsp;您似乎是刚创建这个比赛，请先对比赛信息进行编辑
        </div>
    {% endif %}
    <form id="contest_setting_form" action="{% url 'contest_mgr_save_contest_setting' contest.id %}" method="post">
        <div class="input-group">
            <div class="input-group-addon">比赛名称</div>
            <input type="text" name="title" class="form-control" value="{{ contest.title }}"  maxlength="30">
        </div>
        <br/>
        <div class="input-group">
            <div class="input-group-addon">开始时间</div>
            <input name="start_time" type="text" class="form-control start_time" value="{{ contest.start_time | full_time }}">
            <div class="input-group-addon">结束时间</div>
            <input name="end_time" type="text" class="form-control end_time" value="{{ contest.end_time | full_time }}">
        </div>
        <br>
        <div class="row" align="center">
            <div class="col-sm-4">
                <div class="panel panel-default" style="height: 120px">
                    <br>
                    <h4>评测语言</h4>
                    <input type="checkbox" name="lang" value="gcc" {% if 'gcc' in contest.lang or 'all' in contest.lang %}checked{% endif %}> C语言&nbsp;&nbsp;
                    <input type="checkbox" name="lang" value="gcc-cpp" {% if 'gcc-cpp' in contest.lang or 'all' in contest.lang %}checked{% endif %}> C++&nbsp;&nbsp;
                    <input type="checkbox" name="lang" value="java" {% if 'java' in contest.lang or 'all' in contest.lang %}checked{% endif %}> Java
                    <br><br>
                </div>
            </div>
            <div class="col-sm-4">
                <div class="panel panel-default" style="height: 120px">
                    <br>
                    <h4>暂停评测</h4>
                    <input type="checkbox" name="pause_judge" value="1" {% if contest.pause %}checked{% endif %}>
                    <br><br>
                </div>
            </div>
            <div class="col-sm-4">
                <div class="panel panel-default" style="height: 120px">
                    <br>
                    <h4>公开比赛</h4>
                    <input type="checkbox" name="allow_all_user" value="1" {% if contest.allow_all_user %}checked{% endif %}>
                    <br>(参赛者名单变为排除项)
                </div>
            </div>
        </div>
        <div class="row"  align="center">
            <div class="col-sm-4">
                <div class="panel panel-default" style="height: 120px">
                    <br>
                    <h4>实时查重</h4>
                    <input type="checkbox" name="cross_check" value="1" {% if contest.cross_check %}checked{% endif %}>
                    <br><br>
                </div>
            </div>
            <div class="col-sm-8">
                <div class="panel panel-default" style="height: 120px">
                    <br>
                    <h4>查重记录阈值</h4>
                    <input name="cross_check_ratio" type="text" placeholder="取值0.0 - 1.0" title="取值0.0 - 1.0" value="{{ contest.cross_check_ratio }}" style="text-align: center;">
                    <br><br />
                </div>
            </div>
        </div>
        <div class="panel panel-default">
            <div class="panel-heading">
                <div class="panel-title">查重排除项目</div>
            </div>
            <table class="table table-bordered">
                <thead>
                <tr>
                    <td>ID</td>
                    <td>名称</td>
                    <td>排除？</td>
                </tr>
                </thead>
                <tbody>
                {% for problem in problem_list %}
                <tr>
                    <td>{{ problem.id }}</td>
                    <td>{{ problem.title }}</td>
                    <td><input type="checkbox" name="cc_ignore_problem" value="{{ problem.id }}" {% if problem.id in cc_ignore_problem %}checked{% endif %}></td>
                </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>
        <button type="submit" class="btn btn-success">保存</button>
    </form>
{% endblock %}
{% block contest_page_script %}
    <link rel="stylesheet" href="/static/library/bootstrap-datetimepicker.min.css"/>
    <script src="/static/library/bootstrap-datetimepicker.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="/static/library/jstorage.min.js"></script>
    <script type="text/javascript" src="/static/library/sisyphus.min.js"></script>
    <script type="text/javascript">
        $(function () {
            $(".start_time, .end_time").datetimepicker({
                format: 'yyyy-mm-dd hh:ii:ss',
                minuteStep: 1,
                autoclose: true,
                todayHighlight:true,
                todayBtn:true
            });
            $("#contest_setting_form").submit(function () {
                //for (var ins in CKEDITOR.instances) CKEDITOR.instances[ins].updateElement();
                $.GRestP({
                   responseType: 'json',
                    callback: function (flag, entity) {
                        if(flag){
                            $.AlertBox({
                                body: "比赛参数设置保存成功",
                                color: "success",
                                title: "操作成功",
                                callback: function () {
                                    $(window).unbind('beforeunload');
                                    $.ModalBox({}).hide();
                                    window.location.reload();
                                }
                            }).show();
                        }else{
                            $.AlertBox({body: entity.msg, color: "danger", title: "操作失败"}).show();
                        }
                    }
                }).submit_form(this);
                return false;
            });
        });
    </script>
{% endblock %}